<?php

class TrackController extends AppController
{
    var $uses = array("Post", "Track", "Site", "Like", "Artist");
    var $components = array("Session");
    
    function like($track_id)
    {
        $this->Session->start();
        if ($user = $this->Session->read('User'))
        {
            $user_id = $user['id'];
            var_dump($user);
        }

        $this->Like->save(array(
            'track_id' => $track_id, 
            'date' => date('Y-m-d H:i:s'),
            'user_id' => $user_id));
            
        exit;
    }
    
    function edit($track_id)
    {
	    $post = $_POST;
	    $track = $this->Track->find(array("Track.id" => $track_id));
	    
	    if ($post['Artist-name'] != $track['Track']['artist'])
	    {
		    $artist = $this->Artist->find(array("Artist.name" => $post['Artist-name']));
			   
		    if ($artist)
		    {
		       	$track['Track']['artist_id'] = $artist['Artist']['id'];
			   	$track['Track']['artist'] = $artist['Artist']['name'];
		   	}

		   
	    }
	    
	    $track['Track']['song'] = $post['Track-song'];
	    $track['Track']['status'] = $post['Track-status'];

	    $this->Track->save($track);
	    
	    exit;
    }
}

?>
